Skip to content

fix(forms): render public form embeds via SSR plugin routes#985

Open
ppppangu wants to merge 3 commits into
emdash-cms:mainfrom
ppppangu:fix-public-plugin-routes-ssr
Open

fix(forms): render public form embeds via SSR plugin routes#985
ppppangu wants to merge 3 commits into
emdash-cms:mainfrom
ppppangu:fix-public-plugin-routes-ssr

Conversation

@ppppangu
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes public form embeds during SSR by giving anonymous public pages a restricted way to call public plugin routes. Form embeds now resolve their public definition through the core dispatcher when available, which avoids server-side self-fetching in Worker SSR while preserving the old fetch path for older runtimes or dispatcher failures.

The core helper gates every internal dispatch on getPluginRouteMeta(...).public === true, so private plugin routes still require the normal API route auth, scope, and CSRF path. The forms plugin only calls the fixed emdash-forms /definition route and continues to parse the existing { data: ... } API envelope.

Closes: none

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs; a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: GPT-5 Codex

Screenshots / test output

No screenshots; this is an SSR/plugin route bug fix.

Verification run:

  • pnpm --filter emdash test -- public-plugin-api-routes middleware-prerender passed
  • pnpm --filter @emdash-cms/plugin-forms test -- public-definition passed
  • pnpm --filter @emdash-cms/plugin-forms typecheck passed
  • pnpm --filter emdash build passed
  • pnpm typecheck passed
  • pnpm lint exited with 0 errors; it reports existing warnings outside this change
  • pnpm exec prettier --check on the touched files passed

Notes:

  • I did not run full pnpm format because pnpm format:check reports broad existing formatting drift in this Windows checkout; I kept formatting validation scoped to touched files to avoid unrelated churn.
  • pnpm --filter emdash test currently has unrelated Windows-environment failures in tests/unit/astro/vite-config.test.ts (File URL path must be absolute) and tests/unit/cli/bundle-utils.test.ts (system tar listing CRLF). The targeted core tests for this change pass.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

🦋 Changeset detected

Latest commit: ec13951

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 15 packages
Name Type
emdash Patch
@emdash-cms/plugin-forms Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 11, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@985

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@985

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@985

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@985

emdash

npm i https://pkg.pr.new/emdash@985

create-emdash

npm i https://pkg.pr.new/create-emdash@985

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@985

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@985

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@985

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@985

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@985

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@985

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@985

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@985

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@985

commit: ec13951

@ascorbic
Copy link
Copy Markdown
Collaborator

/review

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Targeted fix for the Workers SSR self-fetch issue, with the wrapped helper correctly gated on getPluginRouteMeta(...).public === true and decent unit coverage on both sides. Two things worth addressing before merge — the silent fallback when the dispatcher throws hides exactly the failures this PR is meant to solve, and Astro.locals.emdash.handlePluginApiRoute now has materially different semantics on the anonymous vs. full middleware paths (public-only vs. raw runtime). A couple of smaller robustness notes inline as well. Nothing here is a blocker.

Comment thread packages/plugins/forms/src/public-definition.ts
Comment thread packages/core/src/astro/middleware.ts Outdated
Comment thread packages/plugins/forms/src/public-definition.ts
Comment thread packages/plugins/forms/src/public-definition.ts
Comment thread packages/plugins/forms/src/astro/FormEmbed.astro Outdated
Comment thread packages/core/tests/unit/astro/middleware-prerender.test.ts
Comment thread packages/core/tests/unit/astro/middleware-prerender.test.ts Outdated
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 11, 2026

Review posted successfully (ID 4263518046, 7 inline comments). The review covers:

  1. Silent dispatcher fallback (public-definition.ts:95) — the catch {} falls back to a fetch path known to be broken on Workers, with no log.
  2. Asymmetric handlePluginApiRoute semantics (middleware.ts:364) — public-only on the anonymous path, raw runtime on the full path; the PR description's security claim only holds for the former.
  3. Permissive payload validation (public-definition.ts:56) — any { status: "active" } is cast to PublicFormDefinition without checking pages/settings, will crash render.
  4. Ambiguous data unwrap recursion (public-definition.ts:49) — fragile if a top-level data field is ever added to the form definition.
  5. Loose as cast in FormEmbed.astro — a future core rename would silently regress to the broken fetch path.
  6. Missing test coverage (middleware-prerender.test.ts:234) — shape-only assertions; the wrapped helper's gating isn't exercised end-to-end here.
  7. Brittle test mock proxy — returns async functions for any symbol/non-string property access.

github run

@github-actions
Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity.

If you're still working on this, please push an update or leave a comment.

@ppppangu ppppangu force-pushed the fix-public-plugin-routes-ssr branch from 42588b0 to ec13951 Compare May 27, 2026 02:08
@ppppangu
Copy link
Copy Markdown
Contributor Author

@ascorbic All 7 review threads have been addressed and resolved, the branch has been rebased, and all CI checks are green. Could you remove the stale “Awaiting author response” label? Thanks!

@github-actions
Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants